﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MulagoDb.model_old;

namespace MulagoDb
{
    public partial class FindPatient : Form
    {
        public static string patienceName = "";
        public static int patientId = 0;
        private ArrayList patients;
        public FindPatient()
        {
            InitializeComponent();
        }

        private void tabPage3_Click(object sender, EventArgs e)
        {
        }
        private void tabControl_indexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Name.Equals("userAccountTab"))
            {
                //MessageBox.Show(this, "You must be a super user to access this tab");
                //tabControl1.SelectedIndex = 0;
            }
        }

        private void searchPnameBtn_Click(object sender, EventArgs e)
        {
            patientListBox.Items.Clear();
           patients =  PatientRegistration.searchPatientName(patientNameTfld.Text,"name");
           if (patients.Count <= 0)
           {
               MessageBox.Show(this, "No patient found with search details");
           }
           else {
               foreach (MulagoDb.model_old.clinicvisit.Patient patient in patients)
               {
                   string patientDetails = patient.getNames() + " " + patient.getScd() + " " + patient.getHospitalNumber();
                   patientListBox.Items.Add(patientDetails);
               }
           }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int index =  patientListBox.SelectedIndex;
            Console.WriteLine("gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"+index);
            if (index >= 0)
            {
                patienceName = ((MulagoDb.model_old.clinicvisit.Patient)patients[index]).getNames();
                patientId = Convert.ToInt32(((MulagoDb.model_old.clinicvisit.Patient)patients[index]).getId());
                //MessageBox.Show(this, "" + index);
                new MulagoMain().Show();
                // System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
            }
            else {
                MessageBox.Show(this, "Please select a Patient");
            }
           

        }

        private void button3_Click(object sender, EventArgs e)
        {
            patienceName = "";
            patientId = 0;
            new MulagoMain().Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabPage3_Click_1(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void FindPatient_Load(object sender, EventArgs e)
        {

        }

        private void searchScdBtn_Click(object sender, EventArgs e)
        {
            patientListBox.Items.Clear();
            patients = PatientRegistration.searchPatientName(scdNumberTfld.Text, "scd");
            if (patients.Count <= 0)
            {
                MessageBox.Show(this, "No patient found with search details");
            }
            else
            {
                foreach (MulagoDb.model_old.clinicvisit.Patient patient in patients)
                {
                    string patientDetails = patient.getNames() + " " + patient.getScd() + " " + patient.getHospitalNumber();
                    patientListBox.Items.Add(patientDetails);
                }
            }
        }

        private void searchDateBtn_Click(object sender, EventArgs e)
        {
            patientListBox.Items.Clear();
            patients = PatientRegistration.searchPatientName(dateVisitPicker.Text, "date");
            if (patients.Count <= 0)
            {
                MessageBox.Show(this, "No patient found with search details");
            }
            else
            {
                foreach (MulagoDb.model_old.clinicvisit.Patient patient in patients)
                {
                    string patientDetails = patient.getNames() + " " + patient.getScd() + " " + patient.getHospitalNumber();
                    patientListBox.Items.Add(patientDetails);
                }
            }
        }

        private void searchPhoneBtn_Click(object sender, EventArgs e)
        {
            patientListBox.Items.Clear();
            patients = PatientRegistration.searchPatientName(phoneNumberTfld.Text, "phone");
            if (patients.Count <= 0)
            {
                MessageBox.Show(this, "No patient found with search details");
            }
            else
            {
                foreach (MulagoDb.model_old.clinicvisit.Patient patient in patients)
                {
                    string patientDetails = patient.getNames() + " " + patient.getPhoneNum() + " " + patient.getHospitalNumber();
                    patientListBox.Items.Add(patientDetails);
                }
            }

        }

        private void patientListBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
    }
}
